home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / idcutils.zip / YESNO.ASM < prev    next >
Assembly Source File  |  1989-02-02  |  4KB  |  184 lines

  1. ;Program        : YESNO.ASM
  2. ;Author            : Gary Conway
  3. ;Created        : 11.07.86
  4. ;Updated        : 02.02.89
  5. ;Notice            : Copyright 1986-1989 Infinity Design Concepts
  6. ;              All Rights Reserved
  7. ;Environ        : COM
  8.  
  9.  
  10. MajVer        Equ    1
  11. MinVer        Equ    1
  12.  
  13.  
  14. comment    \
  15.  
  16.     This program will execute a command line and then return an
  17.     errorlevel that can be read by a batch file errorlevel function.
  18.     Useful in batch files when the user needs to respond to some 
  19.     question and would like access to the users response.
  20.         The response returned is an ASCII char in decimal, i.e.
  21.  
  22. .... a portion of a batch file
  23.  
  24.     YESNO RESP "Do you want the money ? " ( YESNO gets users answer)
  25.     IF ERRORLEVEL 59 ECHO I will give it to you then
  26.     IF ERRORLEVEL 78 ECHO Ok, then don't take it
  27.  
  28. .. 59 and 78 above are the ASCII chars Y and N
  29.  
  30.     For more examples of how to use YESNO, see the FLOPPY.BAT file, also
  31.     in this ARChive.
  32.     
  33. RETURN CODES:
  34.             0 - No response asked for
  35.          Non Zero - Errorlevel is the actual character
  36.             entered by the user.  It  has been 
  37.             converted to upper case and is  in
  38.             decimal  --- (when accessed by the 
  39.             ERRORLEVEL function in BATch files).
  40.  
  41.  
  42. SYNTAX:    yesno resp "What is your answer ? "
  43.     ---- waits for reply from user 
  44.  
  45.     yesno 27 "[31m" "Does not wait here" 13 10
  46.     ---- simply prints message in ANSI color and then CR,LF
  47.  
  48.     yesno resp 13 10 "What is your reply ?"
  49.     ---- sends CR,LF and prompt and waits for reply
  50.  
  51.     yesno 13 "N" 13 | FORMAT A:
  52.     ---- formats the disk in A with no user intervention
  53.  
  54. NOTES:    any ALT-permissable value may be used on the command line
  55.  
  56.     \
  57.  
  58. CR        Equ    13
  59. LF        Equ    10
  60.  
  61.  
  62. CSEG    SEGMENT PARA PUBLIC 'CODE'
  63.     ASSUME CS:CSEG,DS:CSEG,SS:CSEG,ES:CSEG
  64.  
  65. .xlist
  66. .xcref
  67.  
  68.     ORG    100H            ;SKIP TO END OF THE PSP
  69.  
  70. START    PROC    NEAR
  71.  
  72.         Jmp    GO
  73.  
  74.         DB    cr,lf
  75.         DB    "YESNO.COM - batch file enhancer version "
  76.         DB    MajVer+"0",".",MinVer+"0",cr,lf
  77.         DB    "Copyright 1986-1989 Infinity Design Concepts ",cr,lf
  78.         DB    "All Rights Reserved.",cr,lf
  79.         DB    "1052 Parkway Drive ",cr,lf
  80.         DB    "Louisville, Kentucky 40217 ",cr,lf
  81.         DB    "(502) 636-1234",cr,lf
  82.         DB    1Ah
  83.  
  84. GO:
  85.  
  86.         Mov    SI,81h        ;check for response trigger
  87.         Cld
  88. SkipSpace:    Lodsb
  89.         Call    Case
  90.         Cmp    AL,' '
  91.         Je    SkipSpace
  92.         Cmp    AL,'R'
  93.         Jne    NoResponse
  94.         Lodsb
  95.         Call    Case
  96.         Cmp    AL,'E'
  97.         Jne    NoResponse
  98.         Lodsb
  99.         Call    Case
  100.         Cmp    AL,'S'
  101.         Jne    NoResponse
  102.         Lodsb
  103.         Call    Case
  104.         Cmp    AL,'P'
  105.         Jne    NoResponse
  106. ;get here then user wishes an answer to a question
  107.         Mov    RespFlag,1
  108.         Je    YesResponse
  109.  
  110. NoResponse:    Mov    SI,81h
  111.         Mov    RespFlag,0
  112. YesResponse:    Mov    BX,0
  113.         Mov    CH,0
  114. Parse:        Lodsb            ;get next char from command line
  115. Parse1:        Cmp    AL,0Dh
  116.         Jz    RealCR
  117.         Cmp    AL,22h        ;quote ?
  118.         Jnz    NoQuote
  119.         Cmp    CH,1        ;have end " in AL, is this pass 1 ?
  120.         Jnz    Pass0        ;nope, it is pass 0
  121.         Lodsb            ;get next char
  122.         Cmp    AL,22h        ;is it quote ?
  123.         Jz    YesQuote    ;yup
  124.         Xor    CH,1        ;toggle CH back to 0
  125.         Jmp    Parse1
  126. Pass0:        Xor    CH,1        ;toggle CH (make it 1 for inside " "'s)
  127.         Jmp    Alpha
  128. NoQuote:    Cmp    CH,1        ;is CH = 1 ?
  129.         Jnz    CheckNumeric    ;nope
  130. YesQuote:    Mov    DL,AL
  131.         Mov    AH,2
  132.         Int    21h        ;print char
  133.         Jmp    Parse
  134. CheckNumeric:    Cmp    AL,'0'        ;lower end of numerics ?
  135.         Jl    Alpha        ;jmp if below 30H
  136.         Cmp    AL,'9'
  137.         Jg    Alpha        ;jmp if above 39H
  138.         And    AL,0Fh        ;zero high nibble
  139.         Xchg    BX,AX        ;give BL char to convert
  140.         Mov    BH,10
  141.         Mul    BH        ;AX = AX * 10
  142.         Xchg    BX,AX
  143.         Add    BL,AL
  144.         Mov    BH,1        ;flag working on decimal conversion
  145.         Jmp    Parse
  146. Alpha:        Cmp    BH,0        ;0 if " char is in AL
  147.         Jz    Parse        ;so go get next char
  148.         Mov    DL,BL
  149.         Mov    AH,2
  150.         Int    21h        ;print char
  151.         Mov    BX,0
  152.         Jmp    Parse
  153. RealCR:        Cmp    BH,0
  154.         Jz    Exit
  155.         Mov    DL,BL
  156.         Mov    AH,2
  157.         Int    21h
  158. Exit:        Mov    AL,0        ;0 says errorlevel 0 (no reply)
  159.         Cmp    RespFlag,1    ;if 1 then ask for user reply
  160.         Jne    ErrorLevelExit
  161.         Mov    AH,1
  162.         Int    21h        ;wait for user response
  163.         Call    Case
  164.                     ;user char is the error level
  165. ErrorLevelExit:    Mov    AH,4Ch
  166.         Int    21h        ;terminate, passing ERRORlevel in AL
  167.         
  168.  
  169. Case:        Cmp    AL,'a'        ;convert char to upper case
  170.         Jl    GoBack
  171.         Cmp    AL,'z'
  172.         Jg    Goback
  173.         Sub    AL,20h
  174. Goback:        Ret
  175.  
  176.  
  177. START    ENDP
  178.  
  179. RespFlag    DB    0
  180.  
  181.  
  182. CSEG    ENDS
  183.     END    start
  184.